package cn.zhengzhou.springbootmybatis.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("唱歌", 100);
        map.put("一天", 18);
        map.put("忒三公主", 99);
        map.put("我的家",565);
        //1.使用keySet将所有的键放到一起

        Set<String> keys = map.keySet();
        //2.遍历set集合，得到每一个键
        for (Object key : keys) {
            //3.根据键去找值
            Integer value = map.get(key);
            System.out.println(key + ":" + value);
        }
        //entrySet()遍历
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
        //lambda遍历
        map.forEach((k,v) -> System.out.println(k + ":" + v));
    }
}
